//
//  ScrollCardView.swift
//  Speek
//
//  Created by MikeHo on 2023/6/28.
//

import SwiftUI

struct ScrollCardView: View {
    
    @State var sameDateBill: MonthlyBill
    @Binding var isShowDateSelect: Bool
    //@Binding var selectYear: String
    //@Binding var selectMonth: String

    var body: some View {
        VStack{
            //账单日期
            HStack{
                Rectangle()
                    .frame(height: 2)
                    .overlay{
                        Rectangle()
                            .fill(.purple)
                    }
                Button {
                    isShowDateSelect = true
                    //让日期选择器显示当前选择的日期
                   // selectYear = sameDateBill.year
                    //selectMonth = sameDateBill.month
                } label: {
                    Text(sameDateBill.year + "年" + sameDateBill.month + "月")
                        .font(.headline)
                        .foregroundColor(.white)
                        .padding(3)
                }
                .background(
                    RoundedRectangle(cornerRadius: 3)
                        .stroke(Color.purple, lineWidth: 2)
                )
                Rectangle()
                    .frame(height: 2)
                    .overlay{
                        Rectangle()
                            .fill(.purple)
                    }
            }
            .frame(height: 10)
            .padding(.horizontal,2)
            .padding(.top,10)
            
            //当月总支出和收入
            HStack{
                Text("支出:¥\(String(format: "%.2f", sameDateBill.totalOutput))")
                Spacer()
                Text("收入:¥\(String(format: "%.2f", sameDateBill.totalIncome))")
            }
            .padding(.horizontal,5)
            .font(.subheadline)
            
            //当月所有账单
            ForEach(sameDateBill.billsArray){bill in
                BillCardView(bill: bill)
            }
            
        }
    }
}

